/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.abstractvoid.gui;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import pl.abstractvoid.languages.LanguageProvider;

/**
 * Popup Menu for table panel, allows to create AddRemoveRowsQuery JDialog
 * @author Ivo Zieliński
 */
public class InputTablePopupMenu extends JPopupMenu {

    private JMenuItem removeRowsOption;
    private JMenuItem addRowsOption;
    private final JTable table;

    public InputTablePopupMenu(Component comp) {
        table = (JTable) comp;
        removeRowsOption = new JMenuItem(LanguageProvider.getInstance().getString("removeRows"));
        removeRowsOption.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddRemoveRowsQuery rowsDialog = new AddRemoveRowsQuery(true, table);
                UtilsGUI.centerWindow(rowsDialog);
                rowsDialog.setVisible(true);
            }
        });
        add(removeRowsOption);
        addRowsOption = new JMenuItem(LanguageProvider.getInstance().getString("addRows"));
        addRowsOption.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddRemoveRowsQuery rowsDialog = new AddRemoveRowsQuery(false, table);
                UtilsGUI.centerWindow(rowsDialog);
                rowsDialog.setVisible(true);
            }
        });
        add(addRowsOption);
    }
}
